package com.hjwoo.app.views;

import android.os.Bundle;
import android.widget.TextView;

import com.hjwoo.app.R;
import com.hjwoo.app.adpter.OrderStateAdapter;
import com.hjwoo.app.baseviews.BaseAppCompatActivity;
import com.hjwoo.app.been.OrderList;
import com.hjwoo.app.been.OrdersObject;
import com.hjwoo.app.ui.LinearContainer;
import com.hjwoo.app.utils.Utils;

import java.util.ArrayList;
import java.util.List;
import java.util.TimeZone;

/**
 * Created by yangchuan on 2016/5/12.
 * 订单跟踪
 */
public class OrderStateActivity extends BaseAppCompatActivity
{
    private LinearContainer linearContainer;
    private TextView        number, time, type;
    private OrdersObject ordersObject;
    private String stage;

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_orderstate);
        ordersObject = (OrdersObject) getIntent().getSerializableExtra("order");
        stage = getIntent().getStringExtra("stage");
        init();
    }

    private void init()
    {
        Utils.initTitle("订单跟踪", this, true);

        number = (TextView) findViewById(R.id.orderstate_number);//订单编号
        time = (TextView) findViewById(R.id.orderstate_submit_time);//提交时间
        type = (TextView) findViewById(R.id.orderstate_ordertype);//订单状态

        number.setText(ordersObject.getSerialNumber());
        time.setText(Utils.converTime(ordersObject.getCreatedDate(), TimeZone.getTimeZone("GMT+8")));
//        time.setText(Utils.getLocalTimeFromUTC(ordersObject.getCreatedDate()));
        type.setText(stage);
        linearContainer = (LinearContainer) findViewById(R.id.orderstate_linear_addview);
        ContainderSetData();

    }

    //设置数据填充
    private void ContainderSetData()
    {
        List<OrderList> list         = new ArrayList<OrderList>();
        String          orderstate[] = {"评房申请已提交", "评房已完成", "报单申请已提交", "房产初审已完成", "审批已完成", "抵押公证手续已完成", "放款已完成", "返点已完成"};
        String datadetial[] = {
            "极速评房,3秒出值", "即刻报单，享受100%保护期", "马不停蹄的审核中，请您稍候", "若符合黄金屋审核标准，将约定面审时间"
            , "审批流程已完成，将约定下户时间", "公证、抵押登记已完成", "见受理单后即时放款", "订单返点已发放，请及时查收"
        };
        for (int i = 0; i < orderstate.length; i++)
        {
            OrderList orderList = new OrderList();
            orderList.statename = orderstate[i];
            orderList.state = "0";
            orderList.stateStr = datadetial[i];
            list.add(orderList);
        }
//        switch (ordersObject.stage.getName())
//        {
        String stageName = ordersObject.getStage().getName();
        if (stageName.equals( "评房申请已提交")) {
//        case "评房申请已提交":
            //订单结果（Pending/Completed:成功；Failed：失败）
            list.get(0).stateStr = "极速评房，3秒出值";
            if (ordersObject.getStatus().equals("Pending") || ordersObject.getStatus().equals("Completed"))
            {
                list.get(0).state = "1";
                list.get(0).stateStr = "极速评房，3秒出值";
            }
            if (ordersObject.getStatus().equals("Failed"))
            {
                list.get(0).state = "2";
                list.get(0).stateStr = "失败原因:" + ordersObject.getCauseOfFailure().getName();
            }
//            break;
        }else if (stageName.equals( "评房已完成")) {
//        case "评房已完成":
            list.get(1).stateStr = "即刻报单，享受100%保护期";
            list.get(0).state = "1";
            list.get(0).stateStr = "极速评房，3秒出值";
            if (ordersObject.getStatus().equals("Pending") || ordersObject.getStatus().equals("Completed")) {
                list.get(1).state = "1";
                list.get(1).stateStr = "评房结果:" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 0.9) + "~" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 1) + "万元";
            }
            if (ordersObject.getStatus().equals("Failed")) {
                list.get(1).state = "2";
                list.get(1).stateStr = "失败原因:" + ordersObject.getCauseOfFailure().getName();
            }
//            break;
        }else if (stageName.equals( "报单申请已提交")||stageName.equals( "基础材料已提供")||stageName.equals( "征信查询已完成") ||stageName.equals( "信息已完善") ) {
//        case "报单申请已提交":
            list.get(2).stateStr = "马不停蹄的审核中，请您稍候";
            list.get(0).state = "1";
            list.get(0).stateStr = "极速评房，3秒出值";
            list.get(1).state = "1";
            list.get(1).stateStr = "评房结果:" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 0.9) + "~" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 1) + "万元";
            if (ordersObject.getStatus().equals("Pending") || ordersObject.getStatus().equals("Completed")) {
                list.get(2).state = "1";
                list.get(2).stateStr = "马不停蹄的审核中，请稍候";
            }
            if (ordersObject.getStatus().equals("Failed")) {
                list.get(2).state = "2";
                list.get(2).stateStr = "失败原因:" + ordersObject.getCauseOfFailure().getName();
            }
//            break;
        }else if (stageName.equals( "房产初审已完成")||stageName.equals( "预约申请已提交")||stageName.equals( "预约已指派")||stageName.equals( "产调已完成")||stageName.equals( "征信查询已完成")||stageName.equals( "下户已经完成")) {
//        case "房产初审已完成":
            list.get(3).stateStr = "若符合黄金屋审核标准，将约定面审时间";
            list.get(0).state = "1";
            list.get(0).stateStr = "极速评房，3秒出值";
            list.get(1).state = "1";
            list.get(1).stateStr = "评房结果:" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 0.9) + "~" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 1) + "万元";
            list.get(2).state = "1";
            list.get(2).stateStr = "马不停蹄的审核中，请稍候";
            if (ordersObject.getStatus().equals("Pending") || ordersObject.getStatus().equals("Completed")) {
                list.get(3).state = "1";
                list.get(3).stateStr = "最高可贷金额: " + ordersObject.getMaximumAmountOfCredit() + "万元";
            }
            if (ordersObject.getStatus().equals("Failed")) {
                list.get(3).state = "2";
                list.get(3).stateStr = "失败原因:" + ordersObject.getCauseOfFailure().getName();
            }
//            break;
        }else if (stageName.equals( "审批已完成")) {
//        case "审批已完成":
            list.get(4).stateStr = "审批流程已完成，将约定下户时间";
            list.get(0).state = "1";
            list.get(0).stateStr = "极速评房，3秒出值";
            list.get(1).state = "1";
            list.get(1).stateStr = "评房结果:" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 0.9) + "~" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 1) + "万元";
            list.get(2).state = "1";
            list.get(2).stateStr = "马不停蹄的审核中，请稍候";
            list.get(3).state = "1";
            list.get(3).stateStr = "最高可贷金额:" + ordersObject.getMaximumAmountOfCredit() + "万元";
            if (ordersObject.getStatus().equals("Pending") || ordersObject.getStatus().equals("Completed")) {
                list.get(4).state = "1";
                String str = ordersObject.getInterestPaymentMethod() == null ? "暂无付息方式" : ordersObject.getInterestPaymentMethod().getName();
                list.get(4).stateStr = "放款金额:" + ordersObject.getActualAmountOfCredit() +
                        "万元;" + str +
                        ";月息:" + ordersObject.getMonthlyInterest() +
                        "%;返点点位:" + ordersObject.getCommissionRate() +
                        "%;可提返点:" + ordersObject.getCommission() + "万元。";
//                    list.get(4).stateStr = "放款金额: " + ordersObject.actualAmountOfCredit + "万元;" + "贷款期限" + ordersObject.loanDuration + "个月;" + "返点金额(代发放):" + ordersObject.getCommission() + "万元";
            }
            if (ordersObject.getStatus().equals("Failed")) {
                list.get(4).state = "2";
                list.get(4).stateStr = "失败原因:" + ordersObject.getCauseOfFailure().getName();
            }
//            break;
        }else if (stageName.equals( "抵押公证手续已完成")) {
//        case "抵押公证手续已完成":
            list.get(5).stateStr = "公正、抵押登记已完成";
            list.get(0).state = "1";
            list.get(0).stateStr = "极速评房，3秒出值";
            list.get(1).state = "1";
            list.get(1).stateStr = "评房结果:" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 0.9) + "~" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 1) + "万元";
            list.get(2).state = "1";
            list.get(2).stateStr = "马不停蹄的审核中，请稍候";
            list.get(3).state = "1";
            list.get(3).stateStr = "最高可贷金额:" + ordersObject.getMaximumAmountOfCredit() + "万元";
            list.get(4).state = "1";
            String str = ordersObject.getInterestPaymentMethod() == null ? "暂无付息方式" : ordersObject.getInterestPaymentMethod().getName();
            list.get(4).stateStr = "放款金额:" + ordersObject.getActualAmountOfCredit() +
                    "万元;" + str +
                    ";月息:" + ordersObject.getMonthlyInterest() +
                    "%;返点点位:" + ordersObject.getCommissionRate() +
                    "%;可提返点:" + ordersObject.getCommission() + "万元。";
            if (ordersObject.getStatus().equals("Pending") || ordersObject.getStatus().equals("Completed")) {
                list.get(5).state = "1";
                list.get(5).stateStr = "工作人员会在申请提交后24小时内处理完成";
            }
            if (ordersObject.getStatus().equals("Failed")) {
                list.get(5).state = "2";
                list.get(5).stateStr = "失败原因:" + ordersObject.getCauseOfFailure().getName();
            }
//            break;
        }else if (stageName.equals( "放款已完成")) {
//        case "放款已完成":
            list.get(6).stateStr = "见受理单后即时放款";
            list.get(0).state = "1";
            list.get(0).stateStr = "极速评房，3秒出值";
            list.get(1).state = "1";
            list.get(1).stateStr = "评房结果:" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 0.9) + "~" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 1) + "万元";
            list.get(2).state = "1";
            list.get(2).stateStr = "马不停蹄的审核中，请稍候";
            list.get(3).state = "1";
            list.get(3).stateStr = "最高可贷金额:" + ordersObject.getMaximumAmountOfCredit() + "万元";
            list.get(4).state = "1";
            String str1 = ordersObject.getInterestPaymentMethod() == null ? "暂无付息方式" : ordersObject.getInterestPaymentMethod().getName();
            list.get(4).stateStr = "放款金额:" + ordersObject.getActualAmountOfCredit() +
                    "万元;" + str1 +
                    ";月息:" + ordersObject.getMonthlyInterest() +
                    "%;返点点位:" + ordersObject.getCommissionRate() +
                    "%;可提返点:" + ordersObject.getCommission() + "万元。";
            list.get(5).state = "1";
            list.get(5).stateStr = "工作人员会在申请提交后24小时内处理完成";
            if (ordersObject.getStatus().equals("Pending") || ordersObject.getStatus().equals("Completed")) {
                list.get(6).state = "1";
                list.get(6).stateStr = "评房结果将已短信形式发送到您的手机";
            }
            if (ordersObject.getStatus().equals("Failed")) {
                list.get(6).state = "2";
                list.get(6).stateStr = "失败原因:" + ordersObject.getCauseOfFailure().getName();
            }
//            break;
        }else if (stageName.equals( "返点已完成")) {
//        case "返点已完成":
            list.get(7).stateStr = "订单返点已发放，请及时查收";
            list.get(0).state = "1";
            list.get(0).stateStr = "极速评房，3秒出值";
            list.get(1).state = "1";
            list.get(1).stateStr = "评房结果:" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 0.9) + "~" + (int) (Double.valueOf(ordersObject.getLoanAmount()) * 1) + "万元";
            list.get(2).state = "1";
            list.get(2).stateStr = "马不停蹄的审核中，请稍候";
            list.get(3).state = "1";
            list.get(3).stateStr = "最高可贷金额:" + ordersObject.getMaximumAmountOfCredit() + "万元";
            list.get(4).state = "1";
            String str2 = ordersObject.getInterestPaymentMethod() == null ? "暂无付息方式" : ordersObject.getInterestPaymentMethod().getName();
            list.get(4).stateStr = "放款金额:" + ordersObject.getActualAmountOfCredit() +
                    "万元;" + str2 +
                    ";月息:" + ordersObject.getMonthlyInterest() +
                    "%;返点点位:" + ordersObject.getCommissionRate() +
                    "%;可提返点:" + ordersObject.getCommission() + "万元。";
            list.get(5).state = "1";
            list.get(5).stateStr = "工作人员会在申请提交后24小时内处理完成";
            list.get(6).state = "1";
            list.get(6).stateStr = "评房结果将已短信形式发送到您的手机";
            if (ordersObject.getStatus().equals("Pending") || ordersObject.getStatus().equals("Completed")) {
                list.get(7).state = "1";
                list.get(7).stateStr = "返点金额:" + ordersObject.getCommission() + "万元";
            }
            if (ordersObject.getStatus().equals("Failed")) {
                list.get(7).state = "2";
                list.get(7).stateStr = "失败原因:" + ordersObject.getCauseOfFailure().getName();
            }
        }
        linearContainer.setAdapter(new OrderStateAdapter(OrderStateActivity.this, list));
    }
}
 
